/* global_macros.h */
#ifndef GLOBAL_MACROS_H
#define	GLOBAL_MACROS_H

#include <stdlib.h>
#include <stdio.h>

#define CODE_DELIM 255
#define TABLE_END 254
#define CHAR_SIZE 8

/**
 * Should be called after allocating memory. Checks if this was successfull.
 * If not the program is terminated with an EXIT_FAILURE code.
 *
 * @param VAR - The pointer to the allocated memory.
 * @param FUNCTION - The name of the function in which context the memory was
 *                   allocated.
 */
#define ENSURE_ENOUGH_MEMORY(VAR, FUNCTION) \
{if (VAR == NULL) { printf(FUNCTION ": not enough memory\n"); \
                    exit(EXIT_FAILURE); }}

/**
 * Called after opening a file to check if the operation was successfull.
 * If not the program is terminated with an EXIT_FAILURE code.
 *
 * @param VAR - The FILE pointer.
 * @param FUNCTION - The name of the calling function.
 */
#define CHECK_OPEN_FILE(VAR, FUNCTION) \
{if (VAR == NULL) { printf(FUNCTION ": error while opening file\n"); \
                    exit(EXIT_FAILURE); }}

#endif	/* GLOBAL_MACROS_H */

